package com.jxc.jxc01.grc.web;

import com.alibaba.fastjson.JSON;
import com.jxc.jxc01.grc.entity.Manifest;
import com.jxc.jxc01.grc.entity.Procurement;
import com.jxc.jxc01.grc.entity.RespResult;
import com.jxc.jxc01.grc.entity.Vendor;
import com.jxc.jxc01.grc.service.IManifestService;
import com.jxc.jxc01.grc.service.IProcurementService;
import com.jxc.jxc01.grc.service.impl.IManifestServiceImpl;
import com.jxc.jxc01.grc.service.impl.ProcurementSreviceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet(value = "/queryManifest")
public class QueryManifestServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request,
                           HttpServletResponse response)
            throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();

        RespResult manifests1 = (RespResult)request.getSession().getAttribute("manifests");
//        RespResult manifests1=new RespResult();
//        manifests1.setData(request.getSession().getAttribute("manifests"));

        IManifestService manifestService = new IManifestServiceImpl();

        List<Manifest> manifests = manifestService.queryOneOfInBill();
        System.out.println(manifests);

        if (manifests1 == null){
                int count = manifestService.queryOneOfInBillTotalCount();
                RespResult result = new RespResult();
                result.setCode(0);
                result.setMessage("ok");
                result.setCount(count);
                result.setData(manifests);
                System.out.println(result);
                out.println(JSON.toJSONString(result));
        }else {
//            int count = manifestService.queryOneOfInBillTotalCount();
//            RespResult result = new RespResult();
//            result.setCode(0);
//            result.setMessage("ok");
//            result.setCount(count);
//            result.setData(manifests1);
            out.println(JSON.toJSONString(manifests1));
            //删除session
            request.getSession().invalidate();
        }
        out.close();
    }
}
